#
# GSResultsPolicyBase.py
#

from GSTargetInfoPolicies import GSNoTarget

import copy # For making copies of the target policy

class GSBase:
    def __init__(self):
        pass
    
    # Causes the locally-highlighted to cast the spell using the
    # targets collected in pTarget as a guide.
    def castSpell(self, pTarget):
        raise NotImplementedError

    def onSpellMission(self, pCastingGroup, iData1, iData2, iData3):
        raise NotImplementedError

    def doSpellResults(self, pCastingGroup, pTargetInfo):
        raise NotImplementedError

    def doSpellResultsOnTarget(self, pCastingGroup, pTarget):
        raise NotImplementedError

class GSPushMissionNoTarget(GSBase):
    def __init__(self):
        GSBase.__init__(self)

    def castSpell(self, pTarget):
        self.pushSpellMission(-1, -1, 0)

    def onSpellMission(self, pCastingGroup, iData1, iData2, iData3):
        self.doSpellResults(pCastingGroup, GSNoTarget())

class GSPushMissionWithTarget(GSBase):
    def __init__(self, pTargetInfoPolicy):
        GSBase.__init__(self)
        self.m_pTargetPolicy = pTargetInfoPolicy
        
    def castSpell(self, pTargetInfo):
        self.pushSpellMission(pTargetInfo.getData1(), pTargetInfo.getData2(), pTargetInfo.getData3())

    def onSpellMission(self, pCastingGroup, iData1, iData2, iData3):
        pTargetInfo = copy.copy(self.m_pTargetPolicy)
        pTargetInfo.setTargetWithData(iData1, iData2)
        self.doSpellResults(pCastingGroup, pTargetInfo)

    def doSpellResults(self, pCastingGroup, pTargetInfo):
        pListTargets = pTargetInfo.getAffectedTargetList(pCastingGroup, pCastingGroup.plot())
        for pTarget in pListTargets:
            self.doSpellResultsOnTarget(pCastingGroup, pTarget)
